package com.uuah.server.config.spring.parsers.collection;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.config.ListFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.uuah.server.config.spring.UuahHierarchicalBeanDefinitionParserDelegate;
import com.uuah.server.config.spring.parsers.generic.ChildDefinitionParser;

public class ChildListDefinitionParser extends ChildDefinitionParser {

	public ChildListDefinitionParser(String setterMethod) {
		super(setterMethod, ArrayList.class);
		addBeanFlag(UuahHierarchicalBeanDefinitionParserDelegate.UUAH_NO_RECURSE);
	}

	protected Class getBeanClass(Element element) {
		return ListFactoryBean.class;
	}

	protected void parseChild(Element element, ParserContext parserContext,
			BeanDefinitionBuilder builder) {
		super.parseChild(element, parserContext, builder);
		List parsedList = parserContext.getDelegate().parseListElement(element,
				builder.getRawBeanDefinition());
		builder.addPropertyValue("sourceList", parsedList);
		builder
				.addPropertyValue("targetListClass", super
						.getBeanClass(element));
	}

}
